﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.Data.Core;
using System.Data;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeUpdatUserByUsernameDataAction: BestLifeDataAction<int>
    {
          User GvUser=new User();
         public BestLifeUpdatUserByUsernameDataAction(User PUser)
        {
            GvUser = PUser;
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.UpdateUserPassword";
                LvCommand.Parameters.AddWithValue("@Use_Name", GvUser.Use_Name.ToString());//when passing parameters to the SP
                  LvCommand.Parameters.AddWithValue("@User_Modify", GvUser.User_Modify.ToString());
                LvCommand.Parameters.AddWithValue("@Last_Modify", DateTime.Parse(GvUser.Last_Modify.ToString()));
                LvCommand.Parameters.AddWithValue("@Pas_Word", GvUser.Pas_Word.ToString());
                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 
                
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
